//
//  HomeViewController.swift
//  newSwift
//
//  Created by MAC on 2023/10/18.
//

import UIKit
import SmartCodable


class HomeViewController : BaseViewController{
    
    lazy var rightButton : UIBarButtonItem = {
        let button = UIButton()
        button.setTitle("设备", for: .normal)
        button.titleLabel?.font = .systemFont(ofSize: 16)
        button.setTitleColor(.init(hexString: "#333333"), for: .normal)
        button.addTarget(self, action: #selector(clickDevice), for: .touchUpInside)
        
        return UIBarButtonItem(customView: button)
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        SmartConfig.debugMode = .none
        title = "首页"
        
        self.navigationItem.rightBarButtonItems = [rightButton]
        Task.detached(priority: .background) { [self] in
            await test()
        }
        
    }
    
    @objc func clickDevice() {
        self.navigationController?.pushViewController(SearchBleDeviceVC(), animated: true)
    }
    
    
    func test() async {

        let result = await NetWorkRequest(API.easyRequset, modelType: [ZhihuItemModel].self)
        
        if let models = result.model {
            print("异步请求获取到的模型标题__\(models.map({$0.title ?? ""}))")
        } else {
            print("异步请求获取失败__\(result.response)")
        }

    }
    

}


class ZhihuItemModel: Codable{
    var title:  String?
    var ga_prefix: String?
    var image: String?
    var multipic: String?
    var type: Int?
    var id: Int?
}
